#ifndef NMDEFS_H
#define NMDEFS_H
#pragma pack(push, 1)

#define NM_PLAYER_PORTRAIT_LEN     1024

#define NM_PLAYER_NAME_LEN         32

// Player token length
#define NM_PLAYER_TOKEN_LEN        32

// Net message limit body max length
#define NM_BODY_LIMIT_LEN       1024*2

// Table password len
#define NM_TABLE_PASSWROD_LEN   6

// Major message version
#define NM_VER_MAJOR            0

// Minor message version
#define NM_VER_MINOR            1

// Common message type
#define NM_SUCESS       1000
#define NM_FAIL         1001

// Ashenvale room server net message major type.
//
#define NM_SYS          1
#define NM_PLAYER       2
#define NM_GAME         3
#define NM_BEAT         4

// Ashenvale room server net message minor type.
//
// Sys type
#define NM_SYS_REQUEST_LOGIN                10
#define NM_SYS_REQUEST_LOGIN_SUCCESS        1010
#define NM_SYS_REQUEST_LOGIN_FAIL           1011
#define NM_SYS_SERVER_INFO                  1012

// Player sub type
#define NM_PLAYER_REQUEST_TABLE             10
#define NM_PLAYER_SITDOWN                   11
#define NM_PLAYER_STANDUP                   13
#define NM_PLAYER_READY                     14
#define NM_PLAYER_CANCELREADY               15
#define NM_PLAYER_LEAVE                     16
#define NM_PLAYER_FORCEQUIT                 17
#define NM_PLAYER_REQUEST_TABLE_SUCCESS     1010
#define NM_PLAYER_REQUEST_TABLE_FAIL        1011
#define NM_PLAYER_SITDOWN_FAIL              1013
#define NM_PLAYER_PLAYERINFO                1012
#define NM_PLAYER_PLAYERSTATE               1014


// Net beat message minor type
#define NM_BEAT_REQUEST                 0
#define NM_BEAT_REPLY                   1

#ifdef __cplusplus
extern "C" {
#endif

struct _tag_nm_common_header
{
    //
    unsigned short  version;

    //
    unsigned short  checksum;

    //
    unsigned int    len;

    //
    //
    unsigned int    cmd;

    //
    unsigned char   data[];
};

struct _tag_nm_sys_request_login
{
    //
    unsigned int pid;

    //
    unsigned char token[NM_PLAYER_TOKEN_LEN];
};

struct _tag_nm_player_request_table
{
    //
    unsigned int tid;

    //
    unsigned short playerCount;

    //
    unsigned int score;

    //
    unsigned int time;

    char    create;

    //
    //unsigned char password[TABLE_PASSWORD_LEN];
};

struct _tag_nm_table_info
{
    //
    unsigned int    tid;
    unsigned short  state;
    unsigned int    time;
    unsigned short  playerCount;
    unsigned int    score;
    unsigned int    pid;
    unsigned char   playerName[NM_PLAYER_NAME_LEN];
};

struct _tag_nm_player_info
{
    // Player id.
    unsigned int    id;

    // Table id.
    unsigned int    tid;

    // Chair id.
    unsigned short  cid;

    unsigned char   sex;

    unsigned char   state;

    long long       diamond;

    long long       gold;

    long long       experience;

    char            name[NM_PLAYER_NAME_LEN];

    char            portrait[NM_PLAYER_PORTRAIT_LEN];
};

struct _tag_nm_player_chat
{
    unsigned int    from;
    unsigned int    to;
};

struct _tag_nm_player_sitdown
{
    unsigned int    cid;
};

struct _tag_nm_player_state
{
    unsigned int    id;

    unsigned int    tid;

    unsigned short  cid;

    unsigned char   state;
};

typedef struct _tag_nm_common_header NMCommonHeader;
typedef struct _tag_nm_sys_request_login NMSysRequestLogin;
typedef struct _tag_nm_player_request_table NMPlayerRequestTable;
typedef struct _tag_nm_table_info NMTableInfo;
typedef struct _tag_nm_player_info NMPlayerInfo;
typedef struct _tag_nm_player_chat NMPlayerChat;
typedef struct _tag_nm_player_sitdown NMPlayerSitdown;
typedef struct _tag_nm_player_state NMPlayerState;

#ifdef __cplusplus
}
#endif

#pragma pack(pop)
#endif // NMDEFS_H
